﻿'Interface créer par Caroline St-Yves
'Programmez par Caroline St-Yves
'Date de création : 11 septembre 2012, 8h00 am.
'Date dernière modification : 11 octobre 2012
Imports System.Data.SqlClient
Public Class GestionTypeEmploye
    Dim oLocalContext As DBMainContext
    Public oListTypeEmp As New List(Of Type_Employe)

    Private Sub GestionTypeEmploye_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        oLocalContext = New DBMainContext
        dgvTypeEmp.DataSource = (From u In oLocalContext.Type_Employe Where Not oListTypeEmp.Contains(u) Select u)

        For Each Col As DataGridViewColumn In dgvTypeEmp.Columns
            If Not New List(Of String)(New String() {"Nom_Type"}).Contains(Col.Name) Then
                Col.Visible = False
            End If
        Next
    End Sub

    Private Sub btnSauvegarder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSauvegarder.Click
        oLocalContext.CustomSubmitChanges()
    End Sub

    Private Sub dgvFormation_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTypeEmp.RowValidated
        Try
            oLocalContext.CustomSubmitChanges()

        Catch sqlExp As SqlException

            If (sqlExp.Number = 547) Then

                MsgBox("Cette formation ne peut être supprimé, car il est lié à des enregistrements", MsgBoxStyle.Critical)
                CType(Me.Parent, CustomMessageBox).Close()

            End If

        End Try
    End Sub
    Public Function GetSelectedItems() As List(Of Type_Employe)
        Return (From u As DataGridViewRow In dgvTypeEmp.SelectedRows Select CType(u.DataBoundItem, Type_Employe)).ToList
    End Function
End Class
